package com.sunnay.config;

import com.sunnay.properties.SessionProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

@Configuration
@EnableConfigurationProperties(value = {SessionProperties.class})
public class SessionConfig {

    @Bean
    public CookieSerializer cookieSerializer(SessionProperties sessionProperties){
        DefaultCookieSerializer defaultCookieSerializer = new DefaultCookieSerializer();
        defaultCookieSerializer.setCookieName(sessionProperties.getCookieName());
        defaultCookieSerializer.setDomainName(sessionProperties.getDomainName());
        defaultCookieSerializer.setCookiePath(sessionProperties.getCookiePath());
        return defaultCookieSerializer;
    }
}
